package com.mulanweb.api.module.model;

import com.mulanweb.api.module.model.base.BaseChatHistory;
import com.mulanweb.handler.PostHandler;
import com.mulanweb.handler.wechat.TokenHandler;

import java.util.Map;

/**
 * Created by Administrator on 2016/8/15.
 */
public class ChatHistory extends BaseChatHistory<ChatHistory> {
    public static final ChatHistory dao = new ChatHistory();

    public User getUser(){
        if("2003".equals(getChatType())){
            return User.dao.findFirst("SELECT * FROM `user` WHERE open_id = ?",getFromUseropenId());
        }else if("2002".equals(getChatType())){
            return User.dao.findFirst("SELECT * FROM `user` WHERE open_id = ?",getToUserOpenid());
        }else if("text".equals(getChatType())){
            return User.dao.findFirst("SELECT * FROM `user` WHERE open_id = ?",getFromUseropenId());
        }else{
            return null ;
        }

    }

    public CustomerService getCustomerService(){
        if("2003".equals(getChatType())){
            return  CustomerService.dao.findFirst("SELECT * FROM customer_service WHERE kf_account = ?",getToUserOpenid());
        }else if("2002".equals(getChatType())){
            return  CustomerService.dao.findFirst("SELECT * FROM customer_service WHERE kf_account = ?", getFromUseropenId());
        }else if("text".equals(getChatType())){
            return  CustomerService.dao.findFirst("SELECT * FROM customer_service WHERE kf_account = ?","admin");
        }else{
            return null ;
        }
    }

}
